package com.jcfy.framework.web.page;

import com.jcfy.common.utils.StringUtils;

/**
 * 分页数据
 *
 * @author jcfy
 */
public class PageDomain
{
    /** 当前记录起始索引 */
    private Integer pageNum;
    /** 每页显示记录数 */
    private Integer pageSize;
    /** 排序列(若有多个排序字段时用“,”拼接，数量必须和排序方向字段一致) */
    private String orderByColumn;
    /** 排序的方向 "desc" 或者 "asc". */
    private String isAsc;

    public String getOrderBy()
    {
        if (StringUtils.isEmpty(orderByColumn))
        {
            return "";
        }
        // return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;

        String[] columns = orderByColumn.split(",");
        String[] sorts = isAsc.split(",");
        if (columns.length != sorts.length) {
            return "";
        }
        String orderByColumns = "";
        for (int i = 0; i < columns.length; i++) {
            orderByColumns += StringUtils.toUnderScoreCase(columns[i]) + " " + sorts[i] + ", ";
        }
        return orderByColumns.substring(0, orderByColumns.length() - 2);
    }

    public Integer getPageNum()
    {
        return pageNum;
    }

    public void setPageNum(Integer pageNum)
    {
        this.pageNum = pageNum;
    }

    public Integer getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(Integer pageSize)
    {
        this.pageSize = pageSize;
    }

    public String getOrderByColumn()
    {
        return orderByColumn;
    }

    public void setOrderByColumn(String orderByColumn)
    {
        this.orderByColumn = orderByColumn;
    }

    public String getIsAsc()
    {
        return isAsc;
    }

    public void setIsAsc(String isAsc)
    {
        this.isAsc = isAsc;
    }
}
